import java.util.Arrays;

public class Answer2 {
    //https://www.nowcoder.com/practice/eac1c953170243338f941959146ac4bf?tpId=196&tqId=37143&ru=/exam/oj
    //数组中的最长连续子序列

    public int MLS (int[] arr) {
        Arrays.sort(arr);

        int n = arr.length,ret=0;
        for (int left = 0; left < n; ) {
            int right = left + 1;
            int count = 1;
            while (right < n) {
                if (arr[right] == arr[right - 1]) {
                    right++;
                } else if (arr[right] == arr[right - 1] + 1) {
                    count++;
                    right++;
                } else {
                    break;
                }
            }
            ret=Math.max(ret,count);
            left=right;
        }

        return ret;
    }
}
